<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>7 F | Glossary</title>
<meta name="author" content="psyTeachR Team">
<meta name="description" content="7.1 factor A data type where a specific set of values are stored with labels; An explanatory variable manipulated by the experimenter  7.2 factor (data type) A data type where a specific set of...">
<meta name="generator" content="bookdown 0.24 with bs4_book()">
<meta property="og:title" content="7 F | Glossary">
<meta property="og:type" content="book">
<meta property="og:url" content="https://psyteachr.github.io/glossary/f.html">
<meta property="og:image" content="https://psyteachr.github.io/glossary/images/logos/logo.png">
<meta property="og:description" content="7.1 factor A data type where a specific set of values are stored with labels; An explanatory variable manipulated by the experimenter  7.2 factor (data type) A data type where a specific set of...">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="7 F | Glossary">
<meta name="twitter:description" content="7.1 factor A data type where a specific set of values are stored with labels; An explanatory variable manipulated by the experimenter  7.2 factor (data type) A data type where a specific set of...">
<meta name="twitter:image" content="https://psyteachr.github.io/glossary/images/logos/logo.png">
<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/header-attrs-2.11/header-attrs.js"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="libs/bootstrap-4.6.0/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-4.6.0/bootstrap.bundle.min.js"></script><script src="libs/bs3compat-0.3.1.9000/transition.js"></script><script src="libs/bs3compat-0.3.1.9000/tabs.js"></script><script src="libs/bs3compat-0.3.1.9000/bs3compat.js"></script><link href="libs/bs4_book-1.0.0/bs4_book.css" rel="stylesheet">
<script src="libs/bs4_book-1.0.0/bs4_book.js"></script><script src="libs/kePrint-0.0.1/kePrint.js"></script><link href="libs/lightable-0.0.1/lightable.css" rel="stylesheet">
<!-- Global site tag (gtag.js) - Google Analytics --><script async src="https://www.googletagmanager.com/gtag/js?id=G-6NP3MF25W3"></script><script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-6NP3MF25W3');
    </script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- CSS --><link rel="stylesheet" href="include/psyteachr.css">
<link rel="stylesheet" href="include/webex.css">
<link rel="stylesheet" href="include/style.css">
</head>
<body data-spy="scroll" data-target="#toc">

<div class="container-fluid">
<div class="row">
  <header class="col-sm-12 col-lg-3 sidebar sidebar-book"><a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>

    <div class="d-flex align-items-start justify-content-between">
      <h1>
        <a href="index.html" title="">Glossary</a>
      </h1>
      <button class="btn btn-outline-primary d-lg-none ml-2 mt-1" type="button" data-toggle="collapse" data-target="#main-nav" aria-expanded="true" aria-controls="main-nav"><i class="fas fa-bars"></i><span class="sr-only">Show table of contents</span></button>
    </div>

    <div id="main-nav" class="collapse-lg">
      <form role="search">
        <input id="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
</form>

      <nav aria-label="Table of contents"><h2>Table of contents</h2>
        <ul class="book-toc list-unstyled">
<li><a class="" href="index.html">Overview</a></li>
<li><a class="" href="symbols.html"><span class="header-section-number">1</span> Symbols</a></li>
<li><a class="" href="a.html"><span class="header-section-number">2</span> A</a></li>
<li><a class="" href="b.html"><span class="header-section-number">3</span> B</a></li>
<li><a class="" href="c.html"><span class="header-section-number">4</span> C</a></li>
<li><a class="" href="d.html"><span class="header-section-number">5</span> D</a></li>
<li><a class="" href="e.html"><span class="header-section-number">6</span> E</a></li>
<li><a class="active" href="f.html"><span class="header-section-number">7</span> F</a></li>
<li><a class="" href="g.html"><span class="header-section-number">8</span> G</a></li>
<li><a class="" href="h.html"><span class="header-section-number">9</span> H</a></li>
<li><a class="" href="i.html"><span class="header-section-number">10</span> I</a></li>
<li><a class="" href="j.html"><span class="header-section-number">11</span> J</a></li>
<li><a class="" href="k.html"><span class="header-section-number">12</span> K</a></li>
<li><a class="" href="l.html"><span class="header-section-number">13</span> L</a></li>
<li><a class="" href="m.html"><span class="header-section-number">14</span> M</a></li>
<li><a class="" href="n.html"><span class="header-section-number">15</span> N</a></li>
<li><a class="" href="o.html"><span class="header-section-number">16</span> O</a></li>
<li><a class="" href="p.html"><span class="header-section-number">17</span> P</a></li>
<li><a class="" href="q.html"><span class="header-section-number">18</span> Q</a></li>
<li><a class="" href="r.html"><span class="header-section-number">19</span> R</a></li>
<li><a class="" href="s.html"><span class="header-section-number">20</span> S</a></li>
<li><a class="" href="t.html"><span class="header-section-number">21</span> T</a></li>
<li><a class="" href="u.html"><span class="header-section-number">22</span> U</a></li>
<li><a class="" href="v.html"><span class="header-section-number">23</span> V</a></li>
<li><a class="" href="w.html"><span class="header-section-number">24</span> W</a></li>
<li><a class="" href="x.html"><span class="header-section-number">25</span> X</a></li>
<li><a class="" href="y.html"><span class="header-section-number">26</span> Y</a></li>
<li><a class="" href="z.html"><span class="header-section-number">27</span> Z</a></li>
</ul>

        <div class="book-extra">
          <p><a id="book-repo" href="https://github.com/psyteachr/glossary">View book source <i class="fab fa-github"></i></a></p>
        </div>
      </nav>
</div>
  </header><main class="col-sm-12 col-md-9 col-lg-7" id="content"><div id="f" class="section level1" number="7">
<h1>
<span class="header-section-number">7</span> F<a class="anchor" aria-label="anchor" href="#f"><i class="fas fa-link"></i></a>
</h1>

<div id="factor" class="section level2" number="7.1">
<h2>
<span class="header-section-number">7.1</span> factor<a class="anchor" aria-label="anchor" href="#factor"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A data type where a specific set of values are stored with labels; An explanatory variable manipulated by the experimenter</dfn></p>
</div>
<div id="factor-data-type" class="section level2" number="7.2">
<h2>
<span class="header-section-number">7.2</span> factor (data type)<a class="anchor" aria-label="anchor" href="#factor-data-type"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A data type where a specific set of values are stored with labels</dfn></p>
<p>In tables, you can store strings as <a href="c.html#character">characters</a> or factors.</p>
<div class="sourceCode" id="cb103"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/tibble/man/tibble.html">tibble</a></span><span class="op">(</span>
  chr <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"A"</span>, <span class="st">"B"</span>, <span class="st">"C"</span><span class="op">)</span>,
  fctr <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/factor.html">factor</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"A"</span>, <span class="st">"B"</span>, <span class="st">"C"</span><span class="op">)</span><span class="op">)</span>
<span class="op">)</span></code></pre></div>
<p>If you print a character <a href="v.html#vector">vector</a>, it will have quotes around each values, while a factor vector will show the <a href="l.html#level">Levels</a> after.</p>
<div class="sourceCode" id="cb104"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">data</span><span class="op">$</span><span class="va">chr</span>
<span class="co">#&gt; [1] "A" "B" "C"</span>

<span class="va">data</span><span class="op">$</span><span class="va">fctr</span>
<span class="co">#&gt; [1] A B C</span>
<span class="co">#&gt; Levels: A B C</span></code></pre></div>
<p>In a <a href="t.html#tibble">tibble</a>, these types will have "&lt;chr&gt;" or "&lt;fctr&gt;" under the column header.</p>
<div class="sourceCode" id="cb105"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">data</span></code></pre></div>
<div class="kable-table">
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:left;">
chr
</th>
<th style="text-align:left;">
fctr
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
A
</td>
<td style="text-align:left;">
A
</td>
</tr>
<tr>
<td style="text-align:left;">
B
</td>
<td style="text-align:left;">
B
</td>
</tr>
<tr>
<td style="text-align:left;">
C
</td>
<td style="text-align:left;">
C
</td>
</tr>
</tbody>
</table></div>
</div>
<p>You can convert between characters and factors like this:</p>
<div class="sourceCode" id="cb106"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="fu"><a href="https://rdrr.io/r/base/character.html">as.character</a></span><span class="op">(</span><span class="va">data</span><span class="op">$</span><span class="va">fctr</span><span class="op">)</span>
<span class="co">#&gt; [1] "A" "B" "C"</span>

<span class="co"># set the levels to the order you want</span>
<span class="fu"><a href="https://rdrr.io/r/base/factor.html">factor</a></span><span class="op">(</span><span class="va">data</span><span class="op">$</span><span class="va">chr</span>, levels <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html">c</a></span><span class="op">(</span><span class="st">"C"</span>, <span class="st">"B"</span>, <span class="st">"A"</span><span class="op">)</span><span class="op">)</span>
<span class="co">#&gt; [1] A B C</span>
<span class="co">#&gt; Levels: C B A</span></code></pre></div>
<p><strong>Resources</strong></p>
<ul>
<li>
<a href="https://r4ds.had.co.nz/factors.html">Factors</a> in R for Data Science</li>
</ul>
</div>
<div id="factor-experimental" class="section level2" number="7.3">
<h2>
<span class="header-section-number">7.3</span> factor (experimental)<a class="anchor" aria-label="anchor" href="#factor-experimental"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>An explanatory variable manipulated by the experimenter</dfn></p>
<p>For example, imagine an experiment where you test half of subjects in a dark room with easy, medium, and hard tasks, and the other half in a light room with easy and hard tasks. This experiment has two <strong>factors</strong>: room darkness and task difficulty. The factor of room darkness is <a href="b.html#between-subjects">between subjects</a> and has two <a href="l.html#level">levels</a>: dark and light. The factor of task difficulty is <a href="w.html#within-subjects">within subjects</a> has three levels: easy, medium, and hard.</p>
<p>See <a href="i.html#independent-variable">independent variable</a></p>

</div>
<div id="false-negative" class="section level2" number="7.4">
<h2>
<span class="header-section-number">7.4</span> false negative<a class="anchor" aria-label="anchor" href="#false-negative"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>When a test concludes there is no effect when there really is an effect</dfn></p>
<p>Also called a <a href="t.html#type-ii-error">type II error</a>, but we prefer the more descriptive "false negative".</p>
<p>See also <a href="f.html#false-positive">false positive</a> and <a href="b.html#beta">beta</a>.</p>

</div>
<div id="false-positive" class="section level2" number="7.5">
<h2>
<span class="header-section-number">7.5</span> false positive<a class="anchor" aria-label="anchor" href="#false-positive"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>When a test concludes there is an effect when there really is no effect</dfn></p>
<p>Also called a <a href="t.html#type-i-error">type I error</a>, but we prefer the more descriptive "false positive".</p>
<p>See also <a href="f.html#false-negative">false negative</a> and <a href="a.html#alpha-stats">alpha (stats)</a>.</p>

</div>
<div id="filtering-joins" class="section level2" number="7.6">
<h2>
<span class="header-section-number">7.6</span> filtering joins<a class="anchor" aria-label="anchor" href="#filtering-joins"><i class="fas fa-link"></i></a>
</h2>
<p><dfn><a href="j.html#joins">Joins</a> that act like the <code><a href="https://rdrr.io/pkg/dplyr/man/filter.html">dplyr::filter()</a></code> function in that they remove rows from the data in one table based on the values in another table.</dfn></p>
<p>The result of a filtering join will only contain rows from the left table and have the same number or fewer rows than the left table.</p>
<ul>
<li><a href="a.html#anti_join">anti_join</a></li>
<li><a href="s.html#semi_join">semi_join</a></li>
</ul>
</div>
<div id="fitted-value" class="section level2" number="7.7">
<h2>
<span class="header-section-number">7.7</span> fitted value<a class="anchor" aria-label="anchor" href="#fitted-value"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>The value of the response variable predicted by the model given certain values for any predictor variables.</dfn></p>
<p>If you have a model</p>
<p><span class="math display">\[Y_i = \beta_0 + \beta_1 X_i + e_i\]</span></p>
<p>then the fitted value for observation <span class="math inline">\(i\)</span> equals <span class="math inline">\(\beta_0 + \beta_1 X_i\)</span>; that is, the model's prediction for a residual (<span class="math inline">\(e_i\)</span>) of zero.</p>

</div>
<div id="fixed-effect" class="section level2" number="7.8">
<h2>
<span class="header-section-number">7.8</span> fixed effect<a class="anchor" aria-label="anchor" href="#fixed-effect"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>An effect assumed to be identical over all sampling units.</dfn></p>
<p>In the standard regression model</p>
<p><span class="math display">\[Y_i = \beta_0 + \beta_1 X_i + e_i\]</span></p>
<p>the parameters <span class="math inline">\(\beta_0\)</span> (the intercept) and <span class="math inline">\(\beta_1\)</span> (the slope) are assumed to be constant across all sampling units (e.g. subjects). These are contrasted with <a href="r.html#random%20effect">random effects</a>, which are effects that differ across the units.</p>
<p>In a mixed effects model, you can get a table of just the fixed effects with the code below:</p>
<div class="sourceCode" id="cb107"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">model</span> <span class="op">&lt;-</span> <span class="fu">afex</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/lmerTest/man/lmer.html">lmer</a></span><span class="op">(</span>
  <span class="va">rating</span> <span class="op">~</span> <span class="va">rater_age</span> <span class="op">*</span> <span class="va">face_age</span> <span class="op">+</span> <span class="co"># fixed effects</span>
  <span class="op">(</span><span class="fl">1</span> <span class="op">|</span> <span class="va">rater_id</span><span class="op">)</span> <span class="op">+</span> <span class="op">(</span><span class="fl">1</span> <span class="op">|</span> <span class="va">face_id</span><span class="op">)</span>, <span class="co"># random effects</span>
  data <span class="op">=</span> <span class="fu">faux</span><span class="fu">::</span><span class="va"><a href="https://rdrr.io/pkg/faux/man/fr4.html">fr4</a></span>
<span class="op">)</span>

<span class="fu">broom.mixed</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/generics/man/tidy.html">tidy</a></span><span class="op">(</span><span class="va">model</span>, effects <span class="op">=</span> <span class="st">"fixed"</span><span class="op">)</span></code></pre></div>
<div class="kable-table">
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:left;">
effect
</th>
<th style="text-align:left;">
term
</th>
<th style="text-align:right;">
estimate
</th>
<th style="text-align:right;">
std.error
</th>
<th style="text-align:right;">
statistic
</th>
<th style="text-align:right;">
df
</th>
<th style="text-align:right;">
p.value
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
fixed
</td>
<td style="text-align:left;">
(Intercept)
</td>
<td style="text-align:right;">
3.8109924
</td>
<td style="text-align:right;">
0.8815183
</td>
<td style="text-align:right;">
4.3232142
</td>
<td style="text-align:right;">
92.64738
</td>
<td style="text-align:right;">
0.0000387
</td>
</tr>
<tr>
<td style="text-align:left;">
fixed
</td>
<td style="text-align:left;">
rater_age
</td>
<td style="text-align:right;">
0.0041496
</td>
<td style="text-align:right;">
0.0251227
</td>
<td style="text-align:right;">
0.1651744
</td>
<td style="text-align:right;">
71.11697
</td>
<td style="text-align:right;">
0.8692753
</td>
</tr>
<tr>
<td style="text-align:left;">
fixed
</td>
<td style="text-align:left;">
face_age
</td>
<td style="text-align:right;">
-0.0353353
</td>
<td style="text-align:right;">
0.0252691
</td>
<td style="text-align:right;">
-1.3983587
</td>
<td style="text-align:right;">
92.18523
</td>
<td style="text-align:right;">
0.1653604
</td>
</tr>
<tr>
<td style="text-align:left;">
fixed
</td>
<td style="text-align:left;">
rater_age:face_age
</td>
<td style="text-align:right;">
-0.0003824
</td>
<td style="text-align:right;">
0.0006174
</td>
<td style="text-align:right;">
-0.6194014
</td>
<td style="text-align:right;">
712.00001
</td>
<td style="text-align:right;">
0.5358501
</td>
</tr>
</tbody>
</table></div>
</div>

</div>
<div id="fixed-factor" class="section level2" number="7.9">
<h2>
<span class="header-section-number">7.9</span> fixed factor<a class="anchor" aria-label="anchor" href="#fixed-factor"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A <a href="f.html#factor">factor</a> whose <a href="l.html#level">levels</a> are assumed to represent all the levels of interest in a population; its levels would remain fixed across replications of the study.</dfn></p>
<p>For example, if you were studying the nations making up the United Kingdom, you would have a factor with the levels England, Northern Ireland, Scotland, and Wales. If you would replicate a study, you would include these exact same levels. These four levels represent all the nations comprising the union, and there usually would be no interest in generalizing beyond the data to other (hypothetical) nations.</p>
<p>Fixed factors are usually contrasted with <a href="r.html#random-factor">random factors</a>, whose levels usually are assumed to be the result of (quasi-)random <a href="s.html#sample">sampling</a>.</p>

</div>
<div id="full_join" class="section level2" number="7.10">
<h2>
<span class="header-section-number">7.10</span> full_join<a class="anchor" aria-label="anchor" href="#full_join"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A <a href="m.html#mutating-joins">mutating join</a> that lets you join up rows in two tables while keeping all of the information from both tables</dfn></p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:full-join"></span>
<img src="images/joins/full_join.png" alt="Full Join" width="100%"><p class="caption">
Figure 7.1: Full Join
</p>
</div>
<div class="sourceCode" id="cb108"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="va">X</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/tibble/man/tibble.html">tibble</a></span><span class="op">(</span>
  id <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">5</span>,
  x <span class="op">=</span> <span class="va">LETTERS</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">]</span>
<span class="op">)</span>

<span class="va">Y</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/tibble/man/tibble.html">tibble</a></span><span class="op">(</span>
  id <span class="op">=</span> <span class="fl">2</span><span class="op">:</span><span class="fl">6</span>,
  y <span class="op">=</span> <span class="va">LETTERS</span><span class="op">[</span><span class="fl">22</span><span class="op">:</span><span class="fl">26</span><span class="op">]</span>
<span class="op">)</span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<tr>
<th>
Table X
</th>
<th>
Table Y
</th>

</tr>
<tr>
<td>
<table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
x
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
A
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
B
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
C
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
D
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
E
</td>
</tr>
</tbody>
</table>
</td>
<td>
<table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
y
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
V
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
W
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
X
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
Y
</td>
</tr>
<tr>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
Z
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</table></div>
<p>If there is no matching data in the other table for a row, the values are set to <a href="n.html#na">NA</a>.</p>
<div class="sourceCode" id="cb109"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># a columns come first</span>
<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/dplyr/man/mutate-joins.html">full_join</a></span><span class="op">(</span><span class="va">a</span>, <span class="va">b</span>, by <span class="op">=</span> <span class="st">"id"</span><span class="op">)</span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
x.x
</th>
<th style="text-align:left;">
y
</th>
<th style="text-align:left;">
x.y
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
A
</td>
<td style="text-align:left;">
TRUE
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
B
</td>
<td style="text-align:left;">
TRUE
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
C
</td>
<td style="text-align:left;">
FALSE
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
D
</td>
</tr>
<tr>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
E
</td>
</tr>
<tr>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
F
</td>
</tr>
</tbody>
</table></div>
<p>Order is not important for full joins, but does change the order of columns in the resulting table.</p>
<div class="sourceCode" id="cb110"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span class="co"># b columns come first</span>
<span class="va">data</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/dplyr/man/mutate-joins.html">full_join</a></span><span class="op">(</span><span class="va">b</span>, <span class="va">a</span>, by <span class="op">=</span> <span class="st">"id"</span><span class="op">)</span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<thead><tr>
<th style="text-align:left;">
x.x
</th>
<th style="text-align:right;">
id
</th>
<th style="text-align:left;">
x.y
</th>
<th style="text-align:left;">
y
</th>
</tr></thead>
<tbody>
<tr>
<td style="text-align:left;">
D
</td>
<td style="text-align:right;">
4
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
E
</td>
<td style="text-align:right;">
5
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
F
</td>
<td style="text-align:right;">
6
</td>
<td style="text-align:left;">
NA
</td>
<td style="text-align:left;">
NA
</td>
</tr>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:right;">
1
</td>
<td style="text-align:left;">
A
</td>
<td style="text-align:left;">
TRUE
</td>
</tr>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:right;">
2
</td>
<td style="text-align:left;">
B
</td>
<td style="text-align:left;">
TRUE
</td>
</tr>
<tr>
<td style="text-align:left;">
NA
</td>
<td style="text-align:right;">
3
</td>
<td style="text-align:left;">
C
</td>
<td style="text-align:left;">
FALSE
</td>
</tr>
</tbody>
</table></div>
<p>See <a href="j.html#joins">joins</a> for other types of joins and further resources.</p>

</div>
<div id="function" class="section level2" number="7.11">
<h2>
<span class="header-section-number">7.11</span> function<a class="anchor" aria-label="anchor" href="#function"><i class="fas fa-link"></i></a>
</h2>
<p><dfn>A named section of code that can be reused.</dfn></p>
<p>For example, <code>sd</code> is a function that returns the standard deviation of the <a href="v.html#vector">vector</a> of numbers that you provide as the input <a href="a.html#argument">argument</a>. Functions are set up like this: <code>function_name(argument1 = a1, argument2 = a2)</code>. The <a href="a.html#argument">arguments</a> in parentheses can be named (like, <code>x = c(1,3,5,8)</code>) or you can skip the names if you put them in the exact same order that they're defined in the function. You can check this by typing <code><a href="https://rdrr.io/r/stats/sd.html">?sd</a></code> (or whatever function name you're looking up) into the console and the Help pane will show you the default order under <strong>Usage</strong>.</p>
<div class="figure" style="text-align: center">
<span style="display:block;" id="fig:img-function-help"></span>
<img src="images/defs/function-sd-help.png" alt="Function help" width="100%"><p class="caption">
Figure 7.2: Function help
</p>
</div>

</div>
</div>
<script>

/* update total correct if #webex-total_correct exists */
update_total_correct = function() {
  console.log("webex: update total_correct");

  if (t = document.getElementById("webex-total_correct")) {
    var correct = document.getElementsByClassName("webex-correct").length;
    var solvemes = document.getElementsByClassName("webex-solveme").length;
    var radiogroups = document.getElementsByClassName("webex-radiogroup").length;
    var selects = document.getElementsByClassName("webex-select").length;
    
    t.innerHTML = correct + " of " + (solvemes + radiogroups + selects) + " correct";
  }
}

/* webex-solution button toggling function */
b_func = function() {
  console.log("webex: toggle hide");
  
  var cl = this.parentElement.classList;
  if (cl.contains('open')) {
    cl.remove("open");
  } else {
    cl.add("open");
  }
}

/* function for checking solveme answers */
solveme_func = function(e) {
  console.log("webex: check solveme");

  var real_answers = JSON.parse(this.dataset.answer);
  var my_answer = this.value;
  var cl = this.classList;
  if (cl.contains("ignorecase")) {
    my_answer = my_answer.toLowerCase();
  }
  if (cl.contains("nospaces")) {
    my_answer = my_answer.replace(/ /g, "")
  }

  if (my_answer == "") {
    cl.remove("webex-correct");
    cl.remove("webex-incorrect");
  } else if (real_answers.includes(my_answer)) {
    cl.add("webex-correct");
    cl.remove("webex-incorrect");
  } else {
    cl.add("webex-incorrect");
    cl.remove("webex-correct");
  }

  // match numeric answers within a specified tolerance
  if(this.dataset.tol > 0){
    var tol = JSON.parse(this.dataset.tol);
    var matches = real_answers.map(x => Math.abs(x - my_answer) < tol)
    if (matches.reduce((a, b) => a + b, 0) > 0) {
      cl.add("webex-correct");
    } else {
      cl.remove("webex-correct");
    }
  }

  // added regex bit
  if (cl.contains("regex")){
    answer_regex = RegExp(real_answers.join("|"))
    if (answer_regex.test(my_answer)) {
      cl.add("webex-correct");
    }
  }

  update_total_correct();
}

/* function for checking select answers */
select_func = function(e) {
  console.log("webex: check select");
  
  var cl = this.classList
  
  /* add style */
  cl.remove("webex-incorrect");
  cl.remove("webex-correct");
  if (this.value == "answer") {
    cl.add("webex-correct");
  } else if (this.value != "blank") {
    cl.add("webex-incorrect");
  }
  
  update_total_correct();
}

/* function for checking radiogroups answers */
radiogroups_func = function(e) {
  console.log("webex: check radiogroups");

  var checked_button = document.querySelector('input[name=' + this.id + ']:checked');
  var cl = checked_button.parentElement.classList;
  var labels = checked_button.parentElement.parentElement.children;
  
  /* get rid of styles */
  for (i = 0; i < labels.length; i++) {
    labels[i].classList.remove("webex-incorrect");
    labels[i].classList.remove("webex-correct");
  }
  
  /* add style */
  if (checked_button.value == "answer") {
    cl.add("webex-correct");
  } else {
    cl.add("webex-incorrect");
  }
  
  update_total_correct();
}

window.onload = function() {
  console.log("onload");
  /* set up solution buttons */
  var buttons = document.getElementsByTagName("button");

  for (var i = 0; i < buttons.length; i++) {
    if (buttons[i].parentElement.classList.contains('webex-solution')) {
      buttons[i].onclick = b_func;
    }
  }

  /* set up webex-solveme inputs */
  var solveme = document.getElementsByClassName("webex-solveme");

  for (var i = 0; i < solveme.length; i++) {
    /* make sure input boxes don't auto-anything */
    solveme[i].setAttribute("autocomplete","off");
    solveme[i].setAttribute("autocorrect", "off");
    solveme[i].setAttribute("autocapitalize", "off");
    solveme[i].setAttribute("spellcheck", "false");
    solveme[i].value = "";

    /* adjust answer for ignorecase or nospaces */
    var cl = solveme[i].classList;
    var real_answer = solveme[i].dataset.answer;
    if (cl.contains("ignorecase")) {
      real_answer = real_answer.toLowerCase();
    }
    if (cl.contains("nospaces")) {
      real_answer = real_answer.replace(/ /g, "");
    }
    solveme[i].dataset.answer = real_answer;

    /* attach checking function */
    solveme[i].onkeyup = solveme_func;
    solveme[i].onchange = solveme_func;
  }
  
  /* set up radiogroups */
  var radiogroups = document.getElementsByClassName("webex-radiogroup");
  for (var i = 0; i < radiogroups.length; i++) {
    radiogroups[i].onchange = radiogroups_func;
  }
  
  /* set up selects */
  var selects = document.getElementsByClassName("webex-select");
  for (var i = 0; i < selects.length; i++) {
    selects[i].onchange = select_func;
  }

  update_total_correct();
}

</script><script>
$( document ).ready(function() {
  var cite = ' ';
  var psyteachr = ' <a href="https://psyteachr.github.io/"><img src="images/logos/psyteachr_logo.png" style="height: 31px; color: white;" alt="psyTeachR: Reproducible Research" /></a>';
  var license = ' <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/" target="blank"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png"></a>';

  $("footer div.row div:eq(1) p").html(
    psyteachr + license + cite
  );
  
  $("#toc").appendTo($("#main-nav"));
});
</script><div class="chapter-nav">
<div class="prev"><a href="e.html"><span class="header-section-number">6</span> E</a></div>
<div class="next"><a href="g.html"><span class="header-section-number">8</span> G</a></div>
</div></main><div class="col-md-3 col-lg-2 d-none d-md-block sidebar sidebar-chapter">
    <nav id="toc" data-toggle="toc" aria-label="On this page"><h2>On this page</h2>
      <ul class="nav navbar-nav">
<li><a class="nav-link" href="#f"><span class="header-section-number">7</span> F</a></li>
<li><a class="nav-link" href="#factor"><span class="header-section-number">7.1</span> factor</a></li>
<li><a class="nav-link" href="#factor-data-type"><span class="header-section-number">7.2</span> factor (data type)</a></li>
<li><a class="nav-link" href="#factor-experimental"><span class="header-section-number">7.3</span> factor (experimental)</a></li>
<li><a class="nav-link" href="#false-negative"><span class="header-section-number">7.4</span> false negative</a></li>
<li><a class="nav-link" href="#false-positive"><span class="header-section-number">7.5</span> false positive</a></li>
<li><a class="nav-link" href="#filtering-joins"><span class="header-section-number">7.6</span> filtering joins</a></li>
<li><a class="nav-link" href="#fitted-value"><span class="header-section-number">7.7</span> fitted value</a></li>
<li><a class="nav-link" href="#fixed-effect"><span class="header-section-number">7.8</span> fixed effect</a></li>
<li><a class="nav-link" href="#fixed-factor"><span class="header-section-number">7.9</span> fixed factor</a></li>
<li><a class="nav-link" href="#full_join"><span class="header-section-number">7.10</span> full_join</a></li>
<li><a class="nav-link" href="#function"><span class="header-section-number">7.11</span> function</a></li>
</ul>

      <div class="book-extra">
        <ul class="list-unstyled">
<li><a id="book-source" href="https://github.com/psyteachr/glossary/blob/master/terms/f.Rmd">View source <i class="fab fa-github"></i></a></li>
          <li><a id="book-edit" href="https://github.com/psyteachr/glossary/edit/master/terms/f.Rmd">Edit this page <i class="fab fa-github"></i></a></li>
        </ul>
</div>
    </nav>
</div>

</div>
</div> <!-- .container -->

<footer class="bg-primary text-light mt-5"><div class="container"><div class="row">

  <div class="col-12 col-md-6 mt-3">
    <p>"<strong>Glossary</strong>" was written by psyTeachR Team. It was last built on 2022-02-27.</p>
  </div>

  <div class="col-12 col-md-6 mt-3">
    <p>This book was built by the <a class="text-light" href="https://bookdown.org">bookdown</a> R package.</p>
  </div>

</div></div>
</footer><!-- dynamically load mathjax for compatibility with self-contained --><script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://mathjax.rstudio.com/latest/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script><script type="text/x-mathjax-config">const popovers = document.querySelectorAll('a.footnote-ref[data-toggle="popover"]');
for (let popover of popovers) {
  const div = document.createElement('div');
  div.setAttribute('style', 'position: absolute; top: 0, left:0; width:0, height:0, overflow: hidden; visibility: hidden;');
  div.innerHTML = popover.getAttribute('data-content');

  var has_math = div.querySelector("span.math");
  if (has_math) {
    document.body.appendChild(div);
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, div]);
    MathJax.Hub.Queue(function() {
      popover.setAttribute('data-content', div.innerHTML);
      document.body.removeChild(div);
    })
  }
}
</script>
</body>
</html>
